class Frame{
    constructor(x, y, w, h, workspace, configs, tempconfigs){
        this.elem = document.createElement("div");
        this.elem.style.position = 'absolute';
        this.elem.className = configs.className;
        this._z = -1;
        workspace._add(this);
        this._x=x;
        this._y=y;
        this._w=w;
        this._h=h;
        this._v=true;
        this.parent=workspace;
        this.attachEvents();
        this.configs = {...configs, ...tempconfigs};
        this.x = x;
        this.y = y;
        this.width = w;
        this.height = h;
        this.elem.style.backgroundColor = "#ffffff";
        this.elem.style.visibility = 'visible';
    }
    set x(val){if(typeof val !== 'number' || val < (0 - this.elem.offsetWidth / 2) || val > (this.parent.elem.offsetWidth - this.elem.offsetWidth / 2)) return;this._x=val;this.elem.style.left = val + 'px';}
    set y(val){if(typeof val !== 'number' || val < 0 || val > (this.parent.elem.offsetHeight - this.elem.offsetHeight / 2)) return;this._y=val;this.elem.style.top = val + 'px';}
    set width(val){if(typeof val !== 'number' || val < this.configs.minWidth) return;this._w=val;this.elem.style.width = val + 'px';}
    set height(val){if(typeof val !== 'number' || val < this.configs.minHeight) return;this._h=val;this.elem.style.height = val + 'px';}
    set zIndex(val){this._z=val;this.elem.style.zIndex = val + 1 + '';}
    set visible(val){this._v=!!val;this.elem.style.visibility = val?'visible':'hidden';if(this.configs.onChange)this.configs.onChange();}
    get x(){return this._x;}
    get y(){return this._y;}
    get width(){return this._w;}
    get height(){return this._h;}
    get zIndex(){return this._z;}
    get visible(){return this._v;}
    attachEvents(){
        var self = this;
        this.elem.addEventListener("mousedown", function(){
            self.parent.front(self);
        });
    }
    remove(){
        if(this.beforeRemove) this.beforeRemove(this);
        this.parent.remove(this);
    }
    _del(){
        this.elem.remove();
    }
}
export default Frame;